package com.sunkyc.framework.system.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunkyc.framework.system.entity.SysMenuAncestors;
import com.sunkyc.framework.system.mapper.SysMenuAncestorsMapper;
import com.sunkyc.framework.system.service.SysMenuAncestorsService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 菜单祖级id表 服务实现类
 * </p>
 *
 * @author sunkyc
 * @since 2022-06-08
 */
@Service
@RequiredArgsConstructor
public class SysMenuAncestorsServiceImpl extends ServiceImpl<SysMenuAncestorsMapper, SysMenuAncestors> implements SysMenuAncestorsService {
    private final SysMenuAncestorsMapper baseMapper;


    @Override
    public int addMenuAncestors(SysMenuAncestors sysMenuAncestors) {
        return baseMapper.insert(sysMenuAncestors);
    }

    @Override
    public int deleByMenuId(Long menuId) {
        return baseMapper.delete(Wrappers.lambdaQuery(SysMenuAncestors.class).eq(SysMenuAncestors::getMenuId,menuId));
    }

    @Override
    public List<SysMenuAncestors> queryByMenuId(Long menuId) {
        return baseMapper.selectList(Wrappers.lambdaQuery(SysMenuAncestors.class).eq(SysMenuAncestors::getMenuId,menuId));
    }

    @Override
    public Boolean checkedIsChildren(Long menuId, Long parentId) {
        List<SysMenuAncestors> list = queryByMenuId(parentId);
        for (SysMenuAncestors menuAncestors : list) {
            if(menuAncestors.getMenuAncestorId().equals(menuId)){
                return true;
            }
        }
        return false;
    }
}
